package com.DAO;

import com.Module.AdministorM;
import com.Util.Sql;
import com.Module.Administor;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Administorinfo implements Sql {
    public  List<Administor> lis=new ArrayList<>();
    @Override
    public List<Object> select(String idinfo) {
        List<Object> list=new ArrayList<>();
        DatabaseConnection databaseConnection=new DatabaseConnection();
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            String sql="select * from administor where id="+idinfo;
            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                int id=resultSet.getInt("id");
                String name=resultSet.getString("name");
                String department=resultSet.getString("department");
                String address=resultSet.getString("address");
                int year=resultSet.getInt("year");
                String password=resultSet.getString("password");
                Administor administor=new Administor(id,name,department,address,year,password);
                Object ans=(Object) administor;
                list.add(ans);
            }
            databaseConnection.release(connection,statement,resultSet);
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public void select() {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            String sql="select * from administor";
            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                int id=resultSet.getInt("id");
                String name=resultSet.getString("name");
                String department=resultSet.getString("department");
                String address=resultSet.getString("address");
                int year=resultSet.getInt("year");
                String password=resultSet.getString("password");
                Administor administor=new Administor(id,name,department,address,year,password);
                lis.add(administor);
            }
            databaseConnection.release(connection,statement,resultSet);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public int update() {
        return 0;
    }

    @Override
    public int update(Object obj) {
        return 0;
    }

    @Override
    public int delete(Object obj) {
        return 0;
    }


    @Override
    public int modify(Object obj) {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            AdministorM administorM=(AdministorM) obj;
            String sql="update administor set password='"+administorM.getPassword()+"' where id="+administorM.getId();
            int ans=statement.executeUpdate(sql);
            return  ans;
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }
}
